package com.ybkj.o2o.sales.manager.impl;

import com.ybkj.o2o.sales.common.DataGrid;
import com.ybkj.o2o.sales.entity.ActivityManage;
import com.ybkj.o2o.sales.manager.ActivityManageManager;
import com.ybkj.o2o.sales.service.ActivityManageService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DefaultActivityManageManager implements ActivityManageManager {

  @Autowired
  private ActivityManageService activityManageService;



  @Override
  public DataGrid<ActivityManage> queryActivityManage(String companyIds, String chainedAddress,
      String serviceType, Long sort, String showLocation,Integer page,Integer size, String appKey) {

    Integer offset = 0;
    if (page != null && size != null) {
      offset = (page - 1) * size;
    }
    List<ActivityManage> list =
        activityManageService.selectActivityManage(companyIds, chainedAddress, serviceType, sort,
            showLocation, offset, size, appKey);
    long count =
        activityManageService.countActivityManage(companyIds, chainedAddress, serviceType, sort,
            showLocation, appKey);

    DataGrid<ActivityManage> dataGrid = new DataGrid<ActivityManage>();
    dataGrid.setRows(list);
    dataGrid.setTotal(count);

    return dataGrid;

  }



  @Transactional(rollbackFor = Exception.class)
  public ActivityManage insert(ActivityManage activityManage) {
    activityManageService.insert(activityManage);
    return activityManage;
  }



  @Transactional(rollbackFor = Exception.class)
  public void update(ActivityManage activityManage) {
    activityManageService.update(activityManage);
  }



  @Override
  public ActivityManage findOne(Long id, String appKey) {
    return activityManageService.findOne(id, appKey);
  }

  @Transactional(rollbackFor = Exception.class)
  public void delete(Long id, String appKey) {
    activityManageService.delete(id, appKey);
  }

  @Override
  public ActivityManage findByChainedAddress(String chainedAddress, String appKey) {
    return activityManageService.findByChainedAddress(chainedAddress, appKey);
  }



  @Override
  public DataGrid<ActivityManage> queryByCompanyId(String companyId, String serviceType,
      Integer page, Integer size, String appKey) {
    Integer offset = 0;
    if (page != null && size != null) {
      offset = (page - 1) * size;
    }
    List<ActivityManage> list =
        activityManageService.selectByCompanyId(companyId, serviceType, offset, size, appKey);
    long count = activityManageService.countByCompanyId(companyId, serviceType, appKey);

    DataGrid<ActivityManage> dataGrid = new DataGrid<ActivityManage>();
    dataGrid.setRows(list);
    dataGrid.setTotal(count);

    return dataGrid;
  }

}
